//
//  FighterLUpgradeLayer.cpp
//  airfight
//
//  Created by lahm on 12-11-25.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#include "FighterUpgradeLayer.h"
#include "MenuLayer.h"
#include "MsgBoxLayer.h"

bool FighterUpgradeLayer::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    m_SpriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
    m_SpriteFrameCache->addSpriteFramesWithFile("airfight.plist","airfight.png");
    m_SpriteBatch = CCSpriteBatchNode::create("airfight.png");
    
    CCSprite *back = CCSprite::create();
    back->initWithSpriteFrameName("base.png");
    back->setPosition(ccp(160, 240));
    addChild(back);
    
    CCMenuItemFont::setFontSize(15);
    
    CCLabelTTF *labelTitle = CCLabelTTF::labelWithString("战机升级", CCSize(150, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 30);
    labelTitle->setPosition(ccp(160,380));
    addChild(labelTitle);
    
    m_pLabel1 = CCLabelTTF::labelWithString("活塞180 Lv3", CCSize(100, 50), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter, "", 15);
    m_pLabel1->setPosition(ccp(90, 270));
    addChild(m_pLabel1);
    
    CCSprite *upgrade1Btn = CCSprite::create();
    upgrade1Btn->initWithSpriteFrameName("button.png");
    CCSprite *upgrade1BtnClicked = CCSprite::create();
    upgrade1BtnClicked->initWithSpriteFrameName("button.png");
    upgrade1BtnClicked->setScale(0.95);
    CCMenuItemSprite *upgrade1MenuItem = CCMenuItemSprite::itemWithNormalSprite(upgrade1Btn, upgrade1BtnClicked, upgrade1Btn, this, menu_selector(FighterUpgradeLayer::clickUpgrade1));
    upgrade1MenuItem->setPosition(ccp(220, 270));
    CCLabelTTF *labelUpgrade1 = CCLabelTTF::labelWithString("升级", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelUpgrade1->setPosition(ccp(230, 272));
    
    m_pLabel2 = CCLabelTTF::labelWithString("HP 180   基本攻击 30", CCSize(320, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    m_pLabel2->setPosition(ccp(200, 200));
    addChild(m_pLabel2);
    
    CCLabelTTF *label3 = CCLabelTTF::labelWithString("武器1：激光炮 K1", CCSize(320, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    label3->setPosition(ccp(200, 180));
    addChild(label3);
    
    CCLabelTTF *label4 = CCLabelTTF::labelWithString("武器2：EMP II", CCSize(320, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    label4->setPosition(ccp(200, 160));
    addChild(label4);
    
    CCSprite *backBtn = CCSprite::create();
    backBtn->initWithSpriteFrameName("button.png");
    CCSprite *backBtnClicked = CCSprite::create();
    backBtnClicked->initWithSpriteFrameName("button.png");
    backBtnClicked->setScale(0.95);
    CCMenuItemSprite *backMenuItem = CCMenuItemSprite::itemWithNormalSprite(backBtn, backBtnClicked, backBtn, this, menu_selector(FighterUpgradeLayer::clickBack));
    backMenuItem->setPosition(ccp(220, 70));
    CCLabelTTF *labelBack = CCLabelTTF::labelWithString("返回", CCSize(50, 30), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter, "", 15);
    labelBack->setPosition(ccp(230, 72));
    
    CCMenu *menu = CCMenu::menuWithItems(upgrade1MenuItem, backMenuItem, NULL);
    menu->setPosition(CCPointZero);
    addChild(menu);
    addChild(labelUpgrade1);
    addChild(labelBack);
    
    return true;
}

void FighterUpgradeLayer::startLoading()
{
    
}

void FighterUpgradeLayer::onEnter()
{
    CCLayer::onEnter();
    scheduleOnce(schedule_selector(FighterUpgradeLayer::startLoading), 0);
}

void FighterUpgradeLayer::clickBack()
{
    CCScene *pScene = CCScene::create();
    CCLayer *pLayer = MenuLayer::create();
    pScene->addChild(pLayer);
    CCDirector::sharedDirector()->replaceScene(pScene);
}

void FighterUpgradeLayer::clickUpgrade1()
{
    MsgBoxLayer *msgBox = MsgBoxLayer::node();
    msgBox->initDialog("确定消耗150金币，1000矿石，将活塞180升级到Lv4？", menu_selector(FighterUpgradeLayer::clickOk), NULL);
    addChild(msgBox);
}

void FighterUpgradeLayer::clickOk()
{
    ((FighterUpgradeLayer*)getParent())->m_pLabel1->setString("活塞180 Lv4");
    ((FighterUpgradeLayer*)getParent())->m_pLabel2->setString("HP 200   基本攻击 35");
    removeFromParentAndCleanup(true);
}